<template>
	<view :style="{height: wh +'px'}" class="page">
		<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
			@selection-change="selectionChange">
			<uni-tr>
				<uni-th width="50" align="center" @click="doFilter('num')">序号</uni-th>
				<uni-th width="150" align="center" @click="doFilter('title')">题目</uni-th>
				<uni-th width="50" align="center" @click="doFilter('score')">得分</uni-th>
				<uni-th width="180" align="center" @click="doFilter('date')">日期</uni-th>
				<uni-th width="90" align="center" @click="doFilter('detail')">详情</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in answerList" :key="item.subjectCode">
				<uni-td>
					<view>
						{{ index + 1}}
					</view>
				</uni-td>
				<uni-td>
					<view>
						{{ item.topicTitle }}
					</view>
				</uni-td>
				<uni-td>
					<view>
						{{ item.score }}
					</view>
				</uni-td>
				<uni-td align="center">{{ item.answerTime }}</uni-td>
				<uni-td>
					<view class="uni-group">
						<button class="uni-button" size="mini" type="primary" @click="toAnalysis(item)">查看</button>
					</view>
				</uni-td>
			</uni-tr>
		</uni-table>
	</view>
</template>

<script>
	import {
		getAnswerListApi
	} from '../../common/api/user.js'
	export default {
		data() {
			return {
				answerList: [],
				pageNum: 1,
				finish: false,
				base: false,
				wh: 0,
				renderList: []
			};
		},
		onLoad() {
			let getWindowInfo = uni.getWindowInfo()
			this.wh = getWindowInfo.windowHeight
			this.getAnswerList()
		},
		methods: {
			async getAnswerList(callback) {
				if (this.finish) {
					return uni.$showToast('数据请求中,请稍候...')
				} else if (this.base) {
					return uni.$showToast('已经到底啦')
				}
				this.finish = true
				const res = await getAnswerListApi(this.pageNum)
				if (!res.data.records.length) {
					uni.$showToast('已经到底啦')
					this.base = true
				}
				this.answerList.push(...res.data.records)
				callback && callback()
				this.finish = false
			},
			toAnalysis(item) {
				wx.navigateTo({
					url: `/subpkg/analysis/analysis?subjectCode=${item.subjectCode}&topicTitle=${item.topicTitle}`
				})
			},
			selectionChange(res) {},
		},
		onPullDownRefresh() {
			this.pageNum = 1
			this.finish = false
			this.base = false
			this.answerList = []
			this.getAnswerList(uni.stopPullDownRefresh)
		},
		onReachBottom() {
			this.pageNum = this.pageNum + 1
			this.getAnswerList()
		}
	}
</script>

<style lang="scss" scoped>
	/deep/ .uni-card__header-extra {
		font-size: 40rpx;
		font-weight: 700;

		.uni-card__header-extra-text {
			color: #000 !important;
		}
	}

	.page {
		background-color: #fff;
	}

	.uni-group {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	/deep/ .uni-table-td {
		view {
			overflow: hidden;
			-webkit-line-clamp: 1;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
		}
	}
</style>
